package p270jp.pxv.android.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import java.util.Random;
import p270jp.pxv.android.R;
import p325m0.MutabilityOwnership;
import p506t2.C6218w;
import p506t2.ViewPropertyAnimatorCompat;
import p506t2.ViewPropertyAnimatorListener;

/* compiled from: HeartsAnimationView.kt */
/* renamed from: jp.pxv.android.view.HeartsAnimationView */
/* loaded from: classes2.dex */
public final class HeartsAnimationView extends FrameLayout {

    /* renamed from: a */
    public int f19526a;

    /* renamed from: b */
    public int f19527b;

    /* renamed from: c */
    public int f19528c;

    /* renamed from: d */
    public final int f19529d = getResources().getDimensionPixelOffset(R.dimen.heart_width);

    /* renamed from: e */
    public final int f19530e = getResources().getDimensionPixelOffset(R.dimen.heart_height);

    /* compiled from: HeartsAnimationView.kt */
    /* renamed from: jp.pxv.android.view.HeartsAnimationView$a */
    /* loaded from: classes2.dex */
    public static final class C4374a implements ViewPropertyAnimatorListener {
        public C4374a() {
        }

        @Override // p506t2.ViewPropertyAnimatorListener
        /* renamed from: a */
        public void mo2199a(View view) {
            MutabilityOwnership.m3745m(view, "view");
        }

        @Override // p506t2.ViewPropertyAnimatorListener
        /* renamed from: b */
        public void mo2198b(View view) {
            MutabilityOwnership.m3745m(view, "view");
            HeartsAnimationView.this.removeView(view);
        }

        @Override // p506t2.ViewPropertyAnimatorListener
        /* renamed from: c */
        public void mo2197c(View view) {
            MutabilityOwnership.m3745m(view, "view");
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public HeartsAnimationView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        MutabilityOwnership.m3745m(context, "context");
        if (!isInEditMode()) {
            this.f19526a = getResources().getDimensionPixelOffset(R.dimen.live_animation_transition_x_degree);
            this.f19527b = getResources().getDimensionPixelOffset(R.dimen.live_animation_transition_x_margin);
            this.f19528c = getResources().getDimensionPixelOffset(R.dimen.live_animation_transition_y_degree);
        }
    }

    /* renamed from: a */
    public final void m4493a(int i) {
        ImageView imageView = new ImageView(getContext());
        imageView.setImageResource(R.drawable.ic_live_heart);
        imageView.setLayoutParams(new FrameLayout.LayoutParams(this.f19529d, this.f19530e));
        imageView.setColorFilter(i);
        imageView.setX((((float) getWidth()) - ((float) this.f19527b)) - (((float) this.f19529d) / 2.0f));
        imageView.setY((float) (getHeight() - this.f19530e));
        imageView.setAlpha(0.8f);
        addView(imageView);
        Random random = new Random();
        float nextFloat = 1.4f - ((random.nextFloat() * 0.4f) * 2.0f);
        ViewPropertyAnimatorCompat b = C6218w.m2119b(imageView);
        b.m1977e(2000);
        b.m1976f(new DecelerateInterpolator(random.nextFloat() + 0.5f));
        b.m1981a(0.0f);
        float f = (float) (-random.nextInt(this.f19526a));
        View view = b.f26662a.get();
        if (view != null) {
            view.animate().translationXBy(f);
        }
        b.m1972j((float) random.nextInt(this.f19528c));
        float nextFloat2 = 72.0f - ((random.nextFloat() * 72.0f) * 2.0f);
        View view2 = b.f26662a.get();
        if (view2 != null) {
            view2.animate().rotation(nextFloat2);
        }
        b.m1979c(nextFloat);
        b.m1978d(nextFloat);
        C4374a aVar = new C4374a();
        View view3 = b.f26662a.get();
        if (view3 != null) {
            b.m1974h(view3, aVar);
        }
    }

    @Override // android.view.View, android.view.ViewGroup
    public void onDetachedFromWindow() {
        ViewPropertyAnimator animate;
        int childCount = getChildCount();
        if (childCount > 0) {
            int i = 0;
            while (true) {
                int i2 = i + 1;
                View childAt = getChildAt(i);
                if (!(childAt == null || (animate = childAt.animate()) == null)) {
                    animate.cancel();
                }
                if (i2 >= childCount) {
                    break;
                }
                i = i2;
            }
        }
        super.onDetachedFromWindow();
    }
}
